package org.lex.app.sessions;

import java.awt.Component;

import javax.swing.JTabbedPane;

public class JTabbedPaneSession extends AbstractSession {
	private static final String SELECTED_TAB_INDEX = "selectedTabIndex";

	@Override
	public Session getComponentProperties(Component c) {
		this.clear();
		this.putInt(SELECTED_TAB_INDEX, ((JTabbedPane) c).getSelectedIndex());
		return this;
	}

	@Override
	public void restoreComponent(Component c) {
		int index = this.getInt(SELECTED_TAB_INDEX, -1);
		if (-1 != index) {
			JTabbedPane t = (JTabbedPane) c;
			if (t.getTabCount() > index)
				t.setSelectedIndex(index);
		}
	}
}
